{
  "properties" : { },
  "id" : "9d4469a8b4bd4436b7fa23661234a7f7",
  "script" : null,
  "groupId" : "c19b72332a7b41239243fcc1481980c5",
  "name" : "测试",
  "createTime" : null,
  "updateTime" : 1648534432193,
  "lock" : null,
  "createBy" : null,
  "updateBy" : "admin",
  "path" : "/test",
  "method" : "GET",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 200,\n    \"message\": \"success\",\n    \"data\": [{\n        \"_id\": \"423552d95008f0414c57b316\",\n        \"name\": \"姜娜\",\n        \"cardNo\": \"620202198909090909\",\n        \"mobile\": \"13666666666\",\n        \"samplingCompanyName\": \"华西天府医院\",\n        \"eventCircle\": [\n            [{\n                \"cycleCount\": \"1\",\n                \"cycleStartDate\": \"2022-03-23 11:15:11\",\n                \"cycleEndDate\": \"2022-03-25 11:15:11\"\n            }, {\n                \"cycleCount\": \"2\",\n                \"cycleStartDate\": \"2022-03-24 11:15:11\",\n                \"cycleEndDate\": \"2022-03-24 11:15:11\"\n            }]\n        ]\n    }],\n    \"timestamp\": 1648534424563,\n    \"executeTime\": 31\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "",
        "value" : "",
        "description" : "",
        "required" : false,
        "dataType" : "Object",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ {
          "name" : "_id",
          "value" : "423552d95008f0414c57b316",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "name",
          "value" : "姜娜",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "cardNo",
          "value" : "620202198909090909",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "mobile",
          "value" : "13666666666",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "samplingCompanyName",
          "value" : "华西天府医院",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "eventCircle",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "Array",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ {
            "name" : "",
            "value" : "",
            "description" : "",
            "required" : false,
            "dataType" : "Object",
            "type" : null,
            "defaultValue" : null,
            "validateType" : "",
            "error" : "",
            "expression" : "",
            "children" : [ {
              "name" : "",
              "value" : "",
              "description" : "",
              "required" : false,
              "dataType" : "Object",
              "type" : null,
              "defaultValue" : null,
              "validateType" : "",
              "error" : "",
              "expression" : "",
              "children" : [ {
                "name" : "cycleCount",
                "value" : "1",
                "description" : "",
                "required" : false,
                "dataType" : "String",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              }, {
                "name" : "cycleStartDate",
                "value" : "2022-03-23 11:15:11",
                "description" : "",
                "required" : false,
                "dataType" : "String",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              }, {
                "name" : "cycleEndDate",
                "value" : "2022-03-25 11:15:11",
                "description" : "",
                "required" : false,
                "dataType" : "String",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              } ]
            } ]
          } ]
        } ]
      } ]
    }, {
      "name" : "timestamp",
      "value" : "1648534424563",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "executeTime",
      "value" : "31",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import log;
import mongoTemplete;//引入自定义的mongoTemplete模块
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.data.domain.PageImpl
import org.apache.commons.collections.CollectionUtils;

import org.springframework.data.mongodb.core.aggregation.Aggregation;


var tableName = "test_jingmen_xh";



// var criteria = Criteria.where("_id").is("423552d95008f0414c57b316");
var criteria = Criteria.where("cardType").is("2");
var currentPage = 1;
var pageSize = 10;
// Query query = new Query(criteria);
// var res = mongoTemplete.find(query, tableName);

// var res = mongoTemplete.aggregate(Aggregation.newAggregation(
//         Aggregation.unwind("eventNucleicAcid"),
//         // Aggregation.match(criteria),//先平铺再加查询条件， 不然子集中的条件不生效
//         Aggregation.sort(Sort.by(Sort.Order.desc("$eventNucleicAcid.collectTime"))),
//         Aggregation.addFields()
//             .addField("newField").withValue("我是新建的字段")
//             .addFieldWithValue("samplingCompanyName", "$eventNucleicAcid.samplingCompanyName")
//             .build(),
//         Aggregation.project("name","samplingCompanyName","newField")
//     ),tableName).mappedResults;
var coSort = Sort.by(Sort.Order.desc("$eventNucleicAcid.collectTime"),Sort.Order.desc("$eventCircle.cycleEndDate"));

var res = mongoTemplete.aggregate(Aggregation.newAggregation(
        Aggregation.unwind("$eventNucleicAcid"),
        Aggregation.unwind("$eventCircle"),
        Aggregation.sort(coSort),
        Aggregation.group("_id")//group 自带project效果
            .first("name").as("name")
            .first("cardNo").as("cardNo")
            .first("mobile").as("mobile")
            .first("$eventNucleicAcid.samplingCompanyName").as("samplingCompanyName")
            .addToSet("$eventCircle").as("eventCircle")
    ),tableName).mappedResults; 
return res;